import dayjs from "dayjs";

// 判断日期是否在活动期间内
export const isActivityDate = (startTime: string, endTime: string) => {
  const startDate = dayjs(startTime).valueOf();
  const endDate = dayjs(endTime).valueOf();
  const curDate = dayjs().valueOf();
  console.log(startDate, endDate, curDate, "isActivityDate");
  if (curDate >= startDate && curDate <= endDate) {
    return true;
  } else {
    return false;
  }
};

// 判断图片URL是否404
export const checkImgExists = (imgUrl: string) => {
  let xmlHttp;
  if (window.ActiveXObject) {
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  } else if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
  }
  xmlHttp.open("Get", imgUrl, false);
  xmlHttp.send();
  if (xmlHttp.status == 404) return false;
  else return true;
};
